package cn.innosmart.aq.view.fragment;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;

import cn.innosmart.aq.customize.CustomsizeDialog;

/**
 * Created by David on 2015/7/20.
 */
public class BaseFragment extends Fragment {
    public void loge(String tag, String msg) {
        Log.e(tag, msg);
    }

    public void logv(String tag, String msg) {
        Log.v(tag, msg);
    }

    private Toast mToast;

    public void showToast(String Strmsg) {
        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
        Message msg = mHandler.obtainMessage();
        msg.what = SHOWTOAST;
        msg.obj = Strmsg;
        mHandler.sendMessage(msg);
    }

    private final int SHOWDIALOG = 1;
    private final int SHOWTOAST = 3;
    private final int DISMISSDIALOG = 2;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SHOWDIALOG:
                    loadingDialog.show();
                    break;
                case DISMISSDIALOG:
                    loadingDialog.dismiss();
                    break;
                case SHOWTOAST:
                    String message = (String) msg.obj;
                    mToast = Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT);
                    mToast.show();
                    break;
            }
        }
    };
    private CustomsizeDialog loadingDialog;

    public void showLoadingDialog(Context context) {
        if (loadingDialog == null) {
            loadingDialog = new CustomsizeDialog(context);
            loadingDialog.setCanceledOnTouchOutside(false);
        }
        loadingDialog.setLoadingText(null);
        loadingDialog.setBackGround(null);
        mHandler.sendEmptyMessage(SHOWDIALOG);
    }

    public void hideLoadingDialog() {
        if (loadingDialog != null) {
            mHandler.sendEmptyMessage(DISMISSDIALOG);
        }
    }

    public boolean isDialogShowing() {
        if (loadingDialog != null) {
            return loadingDialog.isShowing();
        } else
            return false;
    }

    protected void refresh(){

    }

    protected  void startModify(boolean startModify){

    }

}
